/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package unilearn.bo;

import java.util.ArrayList;
import java.util.List;
import unilearn.dao.AssignmentDAO;
import unilearn.dao.MarkSheetDAO;
import unilearn.vo.Assignment;
import unilearn.vo.Subject;

/**
 *
 * @author Ming
 */
public class AssignmentManagement {

    private AssignmentDAO assignmentDAO;

    public AssignmentManagement() {
        assignmentDAO = null;
    }

    public AssignmentManagement(AssignmentDAO assignmentDAO, MarkSheetDAO MarkSheetDAO) {
        this();
        this.assignmentDAO = assignmentDAO;
    }

    public void setAssignmentDAO(AssignmentDAO assignmentDAO) {
        this.assignmentDAO = assignmentDAO;
    }

    public List<Assignment> getAllAssignments() throws Exception {
        return assignmentDAO.getAll();
    }

    public List<Assignment> getAssignments(Subject subject) throws Exception {
        List<Assignment> as = assignmentDAO.getAll();
        if ((as == null) || (as.isEmpty())) {
            return null;
        }

        List<Assignment> assigns = new ArrayList();
        for (Assignment a : as) {
            if (a.getSubjectCode().equals(subject.getSubjectCode())) {
                assigns.add(a);
            }
        }

        return assigns;
    }

    public Assignment getAssignment(int id) throws Exception {
        return assignmentDAO.get(id);
    }

    public Assignment createAssignment(Assignment assignment) throws Exception {
        return assignmentDAO.insert(assignment);
    }

    public Assignment updateAssignment(Assignment assignment) throws Exception {
        return assignmentDAO.update(assignment);
    }

    public void removeAssignment(Assignment assignment) throws Exception {
        assignmentDAO.delete(assignment);
    }
}
